import { message } from "antd";
import axios from "axios";
import router from 'umi/router';
const server = axios.create({
    baseURL:'http://123.57.143.201:8888/api/private/v1/'

})
server.interceptors.request.use((config)=>{
    //添加token值内容，header头中
    let token=sessionStorage.getItem("token");

    config.headers["Authorization"]=token
    return config
},(err)=>Promise.reject(err))


server.interceptors.response.use((response)=>{
    let {data}=response
    console.log(response)
    let msg=data.meta.msg
    if (msg==="token无效"){
        // 请求结果失败  执行退出操作，清空token值
        sessionStorage.removeItem("token")
        message.warn(data.meta.msg) 
        router.push("/login")
    }else{
        message.success(data.meta.msg)
        
    }
    return response.data
},(err)=>Promise.reject(err))
export default server